//
//  ViewController.swift
//  AlphaVideo
//
//  Created by len on 05/25/2022.
//  Copyright (c) 2022 len. All rights reserved.
//

import UIKit
import AlphaVideo

class ViewController: UIViewController {
    let list = ["20","21","22","23","24","25","26","27","28"]
    let list1 = [2,2,2,2,3,3,3,1,1]
    var count:Int = 0
    override func viewDidLoad() {
        super.viewDidLoad()
        let animView = AlphaVideoView()
        animView.delegate = self
        animView.backgroundColor = .black

        view.addSubview(animView)
        animView.translatesAutoresizingMaskIntoConstraints = false
        animView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        animView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        animView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
        animView.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
        animView.isUserInteractionEnabled = true
        
        animView.pay(url: "20", type: FromType(rawValue: 2) ?? .center)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

extension ViewController:AlphaVedioPlayerDelegate{
    func vedioPlayerFailed(state: AlphaVedioPlayerState, vedioPlayer: AlphaVideoView) {
        
    }
    
    func vedioPlayerReady(state: AlphaVedioPlayerState, vedioPlayer: AlphaVideoView) {
        vedioPlayer.play()
    }
    
    func playerFinished(vedioPlayer: AlphaVideoView) {
       count += 1
        if list.count > count {
            let str = list[count]
            vedioPlayer.axis = ["24","28"].contains(str) ? .vertical : .horizontal
            vedioPlayer.pay(url: str, type: FromType(rawValue: list1[count]) ?? .center,axis: ["24","28"].contains(str) ? .vertical : .horizontal)
        }
       
    }
    
    
}
